package com.basic.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestInetAddress {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress ia = InetAddress.getLocalHost();
        System.out.println(ia.getHostAddress());
        System.out.println(ia.getHostName());

        //获取百度官网的ip
        InetAddress ia2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ia2.getHostAddress());
        System.out.println(ia2.getHostName());

    }
}
